import request, { requestHttp } from "@/utils/request";
import { ReqPage, ResPage } from "@/api/types";

export interface EvalAppraise {
  id?: number;
  formKey?: string;
  appraiseUserId?: string;
  appraiseType?: string;
  appraiseStatus?: string;
  reviewerList?: EvalAppraiseReviewer[];
  weightGroupId?: number;
  createTime?: string;
  updateTime?: string;
}

export interface EvalAppraiseReviewer {
  roleId?: number;
  userIdList?: number[];
  userList?: any[];
}

export interface ReqEvalAppraiseParams extends ReqPage {
  formKey: string;
}

/**
 * 获取被评人列表
 */
export function listEvalAppraise(params: ReqEvalAppraiseParams) {
  return requestHttp.get<ResPage<EvalAppraise>>("/form/eval/appraise/page", params);
}

/**
 * 获取被评人详情
 * @param id
 */
export function getEvalAppraise(id: number): any {
  return requestHttp.get(`/form/eval/appraise/${id}`);
}

export interface AddAppraiseRequest {
  formKey: string;
  appraiseUserIdList: number[];
}

/**
 * 创建被评人
 * @param data
 */
export function addEvalAppraise(data: AddAppraiseRequest) {
  return requestHttp.post("/form/eval/appraise/add", data);
}

/**
 * 修改被评人
 * @param data
 */
export function updateEvalAppraise(data: any) {
  return requestHttp.post<EvalAppraise>("/form/eval/appraise/update", data);
}

/**
 * 删除被评人
 * @param id
 */
export function delEvalAppraise(id: number | number[]) {
  return requestHttp.post(`/form/eval/appraise/delete/${id}`);
}

/**
 * 设置评价人
 */
export function setReviewerUser(data: EvalAppraise) {
  return requestHttp.post(`/form/eval/appraise/setReviewerUser`, data);
}

/**
 * 导出excel
 */
export function exportAppraise(param: ReqEvalAppraiseParams) {
  return request({
    url: "/form/eval/appraise/export",
    method: "get",
    params: param,
    responseType: "blob"
  });
}

/**
 * 下载导入模板
 */
export function downloadTemplate() {
  return request({
    url: "/form/eval/appraise/import/template",
    method: "get",
    responseType: "blob"
  });
}
